//
import request from '@/utils/request'
import config from './config.js'

const baseApi = config.baseApi

/**
 * GET 根据 code 获取用户信息
 * @returns {Promise<Result>}
 */
export function getContext ({ code, state }) {
  return request({
    url: `${baseApi}/UserInfo/getContext`,
    method: 'get',
    params: { code, state: state || '' }
  })
}

/**
 * GET 根据 code 获取用户地域
 * @returns {Promise<Result>}
 */
export function getGroupNameByUser (params) {
  return request({
    url: '/sys/group/findGroupNameByUser',
    method: 'get',
    params: params
  })
}

/**
 * GET 获取部门信息
 * @returns {Promise<Result>}
 */
export function getDep (depId = '') {
  return request({
    url: `${baseApi}/UserInfo/getDep`,
    method: 'get',
    params: { depId }
  })
}

/**
 * GET 获取部门信息
 * @returns {Promise<Result>}
 */
export function getDepUser (depId = '') {
  return request({
    url: `${baseApi}/UserInfo/getDepUser`,
    method: 'get',
    params: { depId }
  })
}

/**
 * POST 常规登录接口---示例
 * @param {*} param0
 * @returns {Promise<Result>}
 */
export function login ({ userName, password }) {
  const url = 'http://10.10.77.159:8002/oauth2/app/login'
  return request({
    url,
    method: 'post',
    params: {
      flag: '4bb86cdb263f4325a9854780aba05c23'
    },
    data: {
      userName,
      password
    },
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}
